package sdp.group14.management.tenant;
import sdp.group14.R;
import sdp.group14.adapter.TenantRequestListAdapter;
import sdp.group14.appdata.Request;
import sdp.group14.management.HousingManagerApplication;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ListActivity;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.CheckBox;
import android.widget.ImageButton;
import android.widget.TextView;

/**
 * this class is used to display the all the Requests stored in
 * the database
 * @author ste706
 *
 */
public class TenantViewRequestActivity extends Activity{

	private TextView dateTextView, statusTextView, itemTextView, descripTextView, causeTextView, commentTextView;
	private CheckBox allowEnter;
	private Request request;
	/**
	 * called when the class is first created
	 */
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.tenant_request_info);
		setUpViews();
	}		
	
	public void onEditClick(View view)
	{
		try {			
			Intent intent = new Intent(TenantViewRequestActivity.this,
					TenantEditRequestActivity.class);
			
			intent.putExtra("request", request);
			startActivity(intent);
			Log.e("MAD", "pass request to edit request activity");
		} catch (Exception e) {
			Log.e("MAD", "error occurs in pass request to edit request activity");
		}
	}
	
	private void setUpViews()
	{
		request = (Request)this.getIntent().getSerializableExtra("request");
		dateTextView = (TextView)findViewById(R.id.text_reqdate_data);
		dateTextView.setText(request.getreqDate());
		statusTextView = (TextView) findViewById (R.id.text_reqstatus_data);
		statusTextView.setText(request.getreqStatus());
		itemTextView = (TextView) findViewById (R.id.text_reqitem_data);
		itemTextView.setText(request.getreqCategory());
		descripTextView = (TextView) findViewById (R.id.text_reqdescrip_data);
		descripTextView.setText(request.getreqDescription());
		causeTextView = (TextView) findViewById (R.id.text_reqcause_data);
		causeTextView.setText(request.getreqCause());
		commentTextView = (TextView) findViewById (R.id.text_reqcomment_data);
		commentTextView.setText(request.getreqComment());
		allowEnter = (CheckBox) findViewById (R.id.tn_checkbx_allow_enter);
		allowEnter.setChecked(request.isReqAllowEnter() == 1);

		Log.e("StaffViewRequestActivity", "set up views");
	}
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
	    if (keyCode == KeyEvent.KEYCODE_BACK) {
	    	try {			
				Intent intent = new Intent(TenantViewRequestActivity.this,
						TenantRequestListActivity.class);				
				startActivity(intent);
				
			} catch (Exception e) {
				Log.e("tenantViewRequestAct", "error occurs in backing to tenant request list");
			}
	        return true;
	    }
	    return super.onKeyDown(keyCode, event);
	}
	

	
}
